include ../config.mk

dist_srcdir = HOC
dist_FILES = \
	HOC \
	HOC-gnustep.conf \
	HOC-gnustep.conf-inplace \
	HOC-macos.conf \
	HOC-macos.conf-inplace \
	HOC.hs \
	Makefile.in \
	$(NULL)

all: libHOC.a HOC.o

libHOC.a: ghcmake.build-stamp
	find build/objects/ -name \*.o | xargs $(MAKE_STATIC_LIB) libHOC.a

#libHOC.dylib: ghcmake
#	export MACOSX_DEPLOYMENT_TARGET=10.3 && find build/objects/ -name \*.o \#
#       | xargs libtool -dynamic -o libHOC.dylib -undefined dynamic_lookup

HOC.o: libHOC.a
	ld -r -x -o HOC.o $(ALL_LOAD) libHOC.a

ghcmake: ghcmake.build-stamp

ghcmake.build-stamp:
	mkdir -p build/objects
	mkdir -p build/imports
	$(GHC) --make HOC.hs	\
		-odir build/objects -hidir build/imports	\
		-fglasgow-exts -package-name HOC \
		../HOC_cbits/HOC_cbits.o	\
		-I../HOC_cbits	\
		-I../libffi-src/build/include	\
		$(FOUNDATION_INCLUDES) \
		$(FOUNDATION_LIBS)      \
                $(DEFINES)
	touch $@

clean:
	rm -rf libHOC.a HOC.o build \
	    HOC/NewClass_stub.c HOC/NewClass_stub.h \
	    ghcmake.build-stamp

install: all
	mkdir -p $(GHC_LIB_PATH)/HOC
	cp -R libHOC.a HOC.o build/imports \
		$(GHC_LIB_PATH)/HOC/
	ranlib $(GHC_LIB_PATH)/HOC/libHOC.a
	$(GHC_PKG) --update-package	\
			--input-file=HOC-$(PLATFORM).conf
